跳到主要内容

Linux 初始化

携飞仙以遨游,抱明月而长终。

前言

为了解决我的 Linux 系统在迁移时需要重新调配环境的问题,特撰写本文以记录环境调配过程中的各种操作步骤及注意事项。

自动化脚本:https://github.com/kqdssheng/Scripts-Misc/blob/main/sh_linux-init.sh

软件清单

oh-my-zsh、zsh-autosuggestions、tldr、fzf、thefuck、trash-cli、locate、docker

配置过程

(1)全局代理设置

export http_proxy=http://192.168.56.1:7890
export https_proxy=http://192.168.56.1:7890
export no_proxy=192.168.56.1,localhost
export HTTP_PROXY=http://192.168.56.1:7890
export HTTPS_PROXY=http://192.168.56.1:7890
export NO_PROXY=192.168.56.1,localhost

注:由于有些程序(如 wget、apt)默认只识别小写的 http_proxy、https_proxy,而不会识别大写的 HTTP_PROXY、HTTPS_PROXY,为此才将大小写变量同时设置。

(2)安装必要软件

#(1)ohmyzsh 安装
wget https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh
RUNZSH='no' sh install.sh

#(2)ohmyzsh 插件安装
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions

#(3)非 git 软件安装
apt update
apt install -y tealdeer fzf thefuck trash-cli locate

#(4)部分软件初始化
tldr -u
updatedb &

注:(1)ohmyzsh 安装脚本默认的安装路径是 ~/.oh-my-zsh;(2)zsh-autosuggestions 插件的安装路径是 ~/.oh-my-zsh/custom/plugins/zsh-autosuggestions;(3)trash 回收站的路径是 /root/.local/share/Trash;(4)

(3)配置 ohmyzsh

cat ~/.zshrc

# 自定义开始
eval $(thefuck --alias c)
export FZF_COMPLETION_TRIGGER='\'

ZSH_THEME="maran"
plugins=(z fzf aliases tldr themes thefuck zsh-autosuggestions)

alias rm="trash"
alias zshconfig="nano ~/.zshrc"
alias ohmyzsh="cd ~/.oh-my-zsh"
# 自定义结束

(4)配置 ohmyzsh 插件

#(1)插件 zsh-autosuggestions 的高亮显示样式变更
cat ~/.oh-my-zsh/custom/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh

typeset -g ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=#00ff00,bg=black,bold,underline'

#(2)插件 tldr 的快捷键变更
cat ~/.oh-my-zsh/plugins/tldr/tldr.plugin.zsh

bindkey "^t" tldr-command-line

(5)Docker 安装

注:以下步骤均来自 清华大学开源软件镜像站

#(1)卸载之前安装的 docker
for pkg in docker.io docker-doc docker-compose podman-docker containerd runc; do apt-get remove $pkg; done

#(2)安装必须组件
apt install -y ca-certificates curl gnupg

#(3)配置 docker apt 的源
install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg

#注意:如果操作系统是 kali,则在新增 docker 源时,需要将源链接和 stable 之间的代码替换成 buster,否则通过 apt update 更新源时会不成功,以至无法后面的安装动作。非 kali 系统则无需替换。

echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/debian buster stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null

#(4)开始安装
apt-get update
apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

Docker 拉取镜像的镜像加速配置使用工具 chsrc 去更新较为方便。【命令:chsrc set dockerhub

注:如果需要安装特定版本的 docker,建议通过脚本 docker-install 去安装较为方便。同样地,如果操作系统是 kali,那么需要先修改脚本中涉及源配置的 $dist_version 字串为 buster(修改位置在 apt_repo = 字串所在的那行),然后再开始执行安装命令。